<?php

namespace Modules\Core\Services;

use Illuminate\Support\ServiceProvider;

use Illuminate\Http\Request;

use Cache ;
use ThrowException;
use \Modules\Message\Entities\Message;

use Auth;


class MessageService
{
	public function send($from, $to, $messageType, $options)
	{
		$fromUserId = $from ? $from->id : null;
		$fromType = $from ? $from->resourceType() : null;

		$toUserId = $to->id;
		$toType = $to->resourceType();

		$message = [
			'from_id' => $fromUserId,
			'from_type' => $fromType,
			'to_id' => $toUserId,
			'to_type' => $toType,
			'type' => $messageType,
			'title' => @v($options['title']),
			'images' => @v($options['images']),
			'thumb' => @v($options['thumb']),
			'text' => @v($options['text']),
			'options' => @V($options['options'])
		];

		Message::create($message);

		$to->setUnread('message', 1);

		return true;
	}
}
